import jwt from 'jsonwebtoken'
import fs from 'fs'
import path from 'path'

const publicKey = fs.readFileSync(path.join(__dirname, '../../publicKey.pub'))

export let gettoken = (ctx) => {
  let token = jwt.sign({
    userInfo: new Date().getDate().toString()
  }, publicKey, { expiresIn: '7d' })

  ctx.body = {
    result: 'get',
    name: ctx.params.name,
    para: ctx.query,
    token: token
  }
}
